<?php
class VerifyAction extends Action {
	/*
		users	登录后无权限可见
		anonymous 匿名无权限也可见
	*/
    public function _initialize(){
		$actions = array(
			'users'=>array(),
			'anonymous'=>array()
		);
		B('Authenticate', $actions);
	}
	
	//列出审核用户
	public function index(){
		$p = $this->_get('p','intval',1);
		$status = $this->_get('status','intval',0);
		if($status == 0){
			$where = array('status'=>'0');
		}elseif($status == 1){
			$where = array('status'=>'1');
		}elseif($status == 2){
			$where = array('status'=>'2');
		}
		$d_user = D('Verify');
		$userpagelist = $d_user->getMessagePageList($p,$where);
//		dump($userpagelist['messagelist']);exit();
		$this->assign('messagelist', $userpagelist['messagelist']);
		$this->assign('page', $userpagelist['page']);
		$this->assign('status', $status);
		$this->alert = parseAlert();
		$this->display();
	}
	
	public function view(){
		if($_GET['uname']!=''){
			$str=D('Structure');
			$user=D('User')->getOneuser($_GET['uname']);
			$ver=D('Verify');
			$getimg=D('Getimg');
			
			//查上级
			$gid['dep']=$str->getTopposition($user['department_id']);
			foreach($gid['dep']['id'] as $key=>$vv){
				$dname[$key]=$str->getDename($vv);
				$user['dep'] .= ' - '.$dname[$key];
			}
			$user['dep'] = substr($user['dep'], 2);
			$user['pos'] = $str->getPosition_n($user["position_id"]);
			
			if($_GET['user_id']){
				$this->assign('getuid', $_GET['user_id']);
			}
			
			$useredit=$ver->getV($user['verify_id']);
			$useredit=json_decode($useredit["content"],TRUE);
			
			$userimg=$getimg->userimg($user['user_id']);
			$this->assign('userimg', json_decode($userimg['src'],TRUE));
			$this->assign('useredit', $useredit);
			$this->assign('userinfo', $user);
		}
		else{
			alert('error','用户信息获取错误，请联系管理员！',U('core/verify/index'));
		}
		$this->display();
	}
	
	//同意
	public function agree(){
		if($_GET['vid']!=''){
			$m=M('verify');
			$mid=$m->where(array("vid"=>$_GET['vid']))->find();
			if($mid['status']!=0){
				alert('error','已经审核过了，不可重复操作！',U('core/verify/index'));
			}
			
			$data['status']=1;
			$data['uid_agree']=$_SESSION['user_id'];
			$data['update']=time();
			$gosave=M('Verify')->where(array('vid'=>$_GET['vid']))->save($data);
			if($gosave){
				alert('success','操作成功！',U('core/verify/index'));
			}else{
				alert('error','保存信息出错，请联系管理员！',U('core/verify/index'));
			}
		}else{
			alert('error','信息错误，请联系管理员！',U('core/verify/index'));
		}
	}
	
	//不同意
	public function unagree(){
		if($_POST){
			if($_POST['vid']!=''){
				$m=M('verify');
				$mid=$m->where(array("vid"=>$_POST['vid']))->find();
				if($mid['status']!=0){
					alert('error','已经审核过了，不可重复操作！',U('core/verify/index'));
				}
				$data['status']=2;
				$data['msg_back']=$_POST['msg_back'];
				$data['uid_agree']=$_SESSION['user_id'];
				$data['update']=time();
				$gosave=M('Verify')->where(array('vid'=>$_POST['vid']))->save($data);
				if($gosave){
					alert('success','操作成功！',U('core/verify/index'));
				}else{
					alert('error','保存信息出错，请联系管理员！',U('core/verify/index'));
				}
			}else{
				alert('error','信息错误，请联系管理员！',U('core/verify/index'));
			}
		}
		$this->display();
	}
	
	//AJAX获得审核信息
	public function tips(){
		$where['status']=array('eq', 0);
		$tipArr = array();
		$d_message = D('Verify');
		$message = $d_message->getMessageTips($where);
		$tipArr['message'] = $message;
		$this->ajaxReturn($tipArr);
	}
	
}
?>